Hi Jerome,
You seem to be missing the concept that KFLOP C programs run inside KFLOP not the PC. The GCode Interpreter (canon, driver, rs427ngc...files) runs in the PC. KFLOP C programs can not directly access memory variables in the PC.
Your original "Compare" function seems to be dependent on only two Variables NewTool and OldTool. I'm not sure why your new code is involving like 7 different things including an input bit.
I'm assuming this C code will be invoked based on a GCode Tool Change Command such as:
M6T3
In this case the New Tool number of 3 will be downloaded to KFLOP and placed into a KFLOP persist Variable before your C program is invoked. If you configure M6 to use Var 9 then the NewTool value will be placed in persist Variable #9 so you can retrieve it into a variable called NewTool with a C statement like
int NewTool = persist.UserData[9];
OldTool is always a problem with Tool Change Programs as what was the last tool loaded and other conditions must be maintained from one tool change to the next. This is especially complicated when a power cycle might have occurred or something moved manually or removed by the operator and so forth. I assume your M6T0 and M6T99 are meant to help with those cases.
Internal variables within a C program will not necessarily be maintained from one execution of the Program to the next. So some persist Variable should be used to save and retrieve what the last tool was. For example we might use Variable #12. So we will assume the Last Tool was saved there and we can retrieve it with
int OldTool = persist.UserData[12];
If we decide to change tools or whatever we should update this variable when we are finished so it reflects the new state for any tool change that happens in the future. With something like:
persist.UserData[12] = xxxxx;
Let me know how much of this makes sense.
Regards
TK